#include <stack>
#include <iostream>
using namespace std;
#define MAX 100
//直方图的最大矩形面积
int largestRectangleArea(int heights[], int n){
    stack<int> stack;
    stack.push(-1);
    int maxArea = 0;
    for(int i = 0; i < n; i++){
        while(stack.top() != -1 && heights[i] <= heights[stack.top()]){
            int height = heights[stack.top()];
            stack.pop();
            int width = i - stack.top() - 1;
            maxArea = max(maxArea, height * width);
        }
        stack.push(i);
    }
    while(stack.top() != -1){
        int height = heights[stack.top()];
        stack.pop();
        int width = n - stack.top() - 1;
        maxArea = max(maxArea, height * width);
    }
    return maxArea;
}
int lagestArea(int matrix[][MAX], int row, int col){
    int heights[col] = {0};
    int cur = 0;
    int maxArea = 0;
    while(cur < row){
        for(int i = 0; i < col; i++){
            if(matrix[cur][i] == 0)
                heights[i] = 0;
            else
                heights[i]++;
        }
        maxArea = max(maxArea, largestRectangleArea(heights, col));
        cur++;
    }
    return maxArea;
}
int main(){
    int matrix[][MAX] = {
                {1, 0, 1, 0, 0},
                {0, 0, 1, 1, 1},
                {1, 1, 1, 1, 1},
                {1, 0, 0, 1, 0}
    };
    int res = lagestArea(matrix, 4, 5);
    cout<<res<<endl;
    return 0;
}